#ifndef QSHELL_H
#define QSHELL_H
#include "qcmdparser.h"

#include <QHash>
#include <QSocketNotifier>
#include <QThread>

class QShellPrivate;

class QShell : public QObject {
  Q_OBJECT
public:
  explicit QShell(const QString &name = "QShell");
  ~QShell();

public:
  void parse(int argc, char *argv[]);

  QCmdParser &addSubCommand(const QString &cmd);
  template <class T> const T &get(const QString &name) const {
    return mCmdParser.get<T>(name.toStdString());
  }

  QCmdParser &add(const QString &name, char short_name = 0,
                  const QString &desc = "") {
    mCmdParser.add(name, short_name, desc);
    return mCmdParser;
  }

  template <class T>
  QCmdParser &add(const QString &name, char short_name = 0,
                  const QString &desc = "", bool need = true,
                  const T def = T()) {
    mCmdParser.add(name, short_name, desc, need, def,
                   cmdline::default_reader<T>());
    return mCmdParser;
  }

  template <class T, class F>
  QCmdParser &add(const QString &name, char short_name = 0,
                  const QString &desc = "", bool need = true, const T def = T(),
                  F reader = F()) {
    mCmdParser.add(name, short_name, desc, need, def, reader);
    return mCmdParser;
  }

private:
  friend class QShellPrivate;
  QScopedPointer<QShellPrivate> d_ptr;
  QCmdParser mCmdParser;
};

#endif